# -*- coding=utf8 -*-
import tornado.httpserver
import os
import datetime
import time
import json
import tornado.ioloop
import tornado.options
import tornado.web
from models.Item import Item, Session, text
import base64

class DelItemHandler(tornado.web.RequestHandler):
    def get(self):
        greeting = self.get_argument('greeting', 'Hello')
        self.write(greeting + ', friendly user!')

    def post(self):
        ItemO = json.loads(self.request.body)
        s=Session()
        its = s.query(Item).filter_by(id=ItemO['id']).all()
        try:
            for i in its:
                s.delete(i)
                # 同时删除本地存储的文件
                # if os.path.exists(i.picFileName):
                #     os.remove(i.picFileName)
            s.commit()
            ret=dict()
            ret['code']=0
            ret['desc']='删除成功'
            self.write(json.dumps(ret))
        except Exception as e:
            ret=dict()
            ret['code']=1
            ret['desc']=str(e)
            self.write(json.dumps(ret))
